package com.toppitch.site.data;

import java.util.ArrayList;
import java.util.List;

public class Paging {
	private int total;
	private int currentPage;
	private int count;
	private int index;// start from 1

	public List<Paging> createPagingList() {
		List<Paging> list = new ArrayList<Paging>();
		int pageCount = getPageCount();
		if (pageCount > 1) {
			if (currentPage > pageCount) {
				currentPage = 1;
			}
			int min = currentPage - 4;
			int max = currentPage + 5;
			while (min < 1) {
				min++;
				max++;
			}
			while (max > pageCount) {
				max--;
			}
			for (int i = min; i <= max; ++i) {
				Paging p = new Paging();
				p.setCount(count);
				p.setCurrentPage(currentPage);
				p.setIndex(i);
				p.setTotal(total);
				list.add(p);
			}
		}

		return list;
	}

	public boolean isCurrent() {
		return index == count;
	}

	public int getPageCount() {
		return count == 0 || total == 0 ? 0 : ((total - 1) / count) + 1;
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public int getIndex() {
		return index;
	}

	public void setIndex(int index) {
		this.index = index;
	}
}
